﻿#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFile>
#include <QMessageBox>
#include <QTableView>
#include <QToolButton>
#include <QDesktopWidget>
#include <QCheckBox>
#include <QPixmapCache>


#define NUMATTR 12
/***
 * 李云帆 2021.4.11
 * 这份代码是从2021年3月中旬开始写的
 * 前端写不了输入、输出等繁杂的东西
 * 所以看上去没有那么多注释
 * 这是正常现象
 */
MainWindow::MainWindow(QWidget *parent)
    : FramelessWindow(parent)
    , ui(new Ui::MainWindow)
/***
 * 类名：MainWindow
 * 方法：构造函数
 * parent：FramelessWindow 用于快捷地隐藏默认外层框架
 */
{
    //初始化ui，并设置大小信息
    ui->setupUi(this);
    resize( QSize( 1152, 720 ));
    //MaterialDesignReMake
    //下面的几个方法用于初始化动态效果控件
    //具体的实现在具体函数里面看
    barsInit();
    warmingInit();
    snackBarInit();

    //将前端控件与接口类方法相关联
    connectFun();

    //初始化默认主题
    setTheme(0);

    //PageOfButton0-0登录页修改
    //实际上登录页的原始控件都是存在的
    //但是为了只保留新的动态特效控件，我们把原始控件隐藏起来
    //但是不要忘记，直接与接口类方法关联的仍然是原始控件
    //所以下文需要将动效控件与原始控件相关联
    ui->accountLineEdit->hide();
    ui->accountLabel->hide();
    ui->passWordLineEdit->hide();
    ui->passWordLabel->hide();
    ui->loginButton->hide();

    //登录页动效控件的硬编码实现
    //因为是硬编码，所以显得十分冗长，与代码整体风格格格不入
    QtMaterialTextField *accountLineEditM = new QtMaterialTextField;
    accountLineEditM->setLabel("账号");
    accountLineEditM->setMinimumWidth(250);
    accountLineEditM->setStyleSheet("background-color:transparent;");
    ui->loginWidget->layout()->addWidget(accountLineEditM);
    connect(accountLineEditM,&QtMaterialTextField::textChanged,
            ui->accountLineEdit,&QLineEdit::setText);
    QtMaterialTextField *passWordLineEditM = new QtMaterialTextField;
    passWordLineEditM->setLabel("密码");
    passWordLineEditM->setEchoMode(QLineEdit::Password);
    passWordLineEditM->setMinimumWidth(250);
    passWordLineEditM->setStyleSheet("background-color:transparent;");
    ui->loginWidget->layout()->addWidget(passWordLineEditM);
    connect(passWordLineEditM,&QtMaterialTextField::textChanged,
            ui->passWordLineEdit,&QLineEdit::setText);
    QtMaterialFlatButton *loginButtonM = new QtMaterialFlatButton;
    loginButtonM->setText("登录");
    loginButtonM->setHaloVisible(false);
    loginButtonM->setBackgroundMode(Qt::OpaqueMode);
    //loginButtonM->setUseThemeColors(false);
    loginButtonM->setBackgroundColor(QColor(120, 120, 120, 255));
    //loginButtonM->setForegroundColor(QColor(120, 120, 120, 50));
    //QColor里面最大的数字是255
    ui->loginWidget->layout()->addWidget(loginButtonM);
    connect(loginButtonM,&QtMaterialFlatButton::clicked,
            ui->loginButton,&QPushButton::clicked);

    //PageOfButton0-1注册页修改
    //实际上注册页的原始控件都是存在的
    //但是为了只保留新的动态特效控件，我们把原始控件所在的容器隐藏起来
    //但是不要忘记，直接与接口类方法关联的仍然是原始控件
    //所以下文需要将动效控件与原始控件相关联
    ui->registerWidget->hide();
    QtMaterialRadioButton *permissionRadioButtonM1 = new QtMaterialRadioButton;
    QtMaterialRadioButton *permissionRadioButtonM2 = new QtMaterialRadioButton;
    QtMaterialRadioButton *permissionRadioButtonM3 = new QtMaterialRadioButton;
    permissionRadioButtonM1->setText("高级管理员");
    permissionRadioButtonM2->setText("站点管理员");
    permissionRadioButtonM3->setText("客户");
    permissionRadioButtonM3->setChecked(true);
    permissionRadioButtonM1->setTextColor(Qt::white);
    permissionRadioButtonM2->setTextColor(Qt::white);
    permissionRadioButtonM3->setTextColor(Qt::white);
    ui->registerUpWidgetM->layout()->addWidget(permissionRadioButtonM1);
    ui->registerUpWidgetM->layout()->addWidget(permissionRadioButtonM2);
    ui->registerUpWidgetM->layout()->addWidget(permissionRadioButtonM3);
    connect(permissionRadioButtonM1,&QtMaterialRadioButton::toggled,
            [this](){ui->permissionLabelComboBox->setCurrentIndex(0);});
    connect(permissionRadioButtonM2,&QtMaterialRadioButton::toggled,
            [this](){ui->permissionLabelComboBox->setCurrentIndex(1);});
    connect(permissionRadioButtonM3,&QtMaterialRadioButton::toggled,
            [this](){ui->permissionLabelComboBox->setCurrentIndex(2);});
    QtMaterialTextField *accountLineEdit_2M = new QtMaterialTextField;
    accountLineEdit_2M->setLabel("设置账号(20位以内)");
    accountLineEdit_2M->setMinimumWidth(250);
    accountLineEdit_2M->setStyleSheet("background-color:transparent;");
    ui->registerWidgetM->layout()->addWidget(accountLineEdit_2M);
    connect(accountLineEdit_2M,&QtMaterialTextField::textChanged,
            ui->accountLineEdit_2,&QLineEdit::setText);
    QtMaterialTextField *nickNameLabelLineEditM = new QtMaterialTextField;
    nickNameLabelLineEditM->setLabel("设置昵称(20位以内)");
    nickNameLabelLineEditM->setMinimumWidth(250);
    nickNameLabelLineEditM->setStyleSheet("background-color:transparent;");
    ui->registerWidgetM->layout()->addWidget(nickNameLabelLineEditM);
    connect(nickNameLabelLineEditM,&QtMaterialTextField::textChanged,
            ui->nickNameLabelLineEdit,&QLineEdit::setText);
    QtMaterialTextField *passWordLineEdit_2M = new QtMaterialTextField;
    passWordLineEdit_2M->setLabel("设置密码(10位以内)");
    passWordLineEdit_2M->setMinimumWidth(250);
    passWordLineEdit_2M->setStyleSheet("background-color:transparent;");
    ui->registerWidgetM->layout()->addWidget(passWordLineEdit_2M);
    connect(passWordLineEdit_2M,&QtMaterialTextField::textChanged,
            ui->passWordLineEdit_2,&QLineEdit::setText);
    ui->registerWidgetM->layout()->addWidget(ui->siteChooseComboBox);

    QtMaterialFlatButton *registerButtonM = new QtMaterialFlatButton;
    registerButtonM->setText("注册");
    registerButtonM->setHaloVisible(false);
    registerButtonM->setBackgroundMode(Qt::OpaqueMode);
    registerButtonM->setBackgroundColor(QColor(120, 120, 120, 255));
    //QColor里面最大的数字是255
    ui->registerWidgetM->layout()->addWidget(registerButtonM);
    connect(registerButtonM,&QtMaterialFlatButton::clicked,
            ui->registerButton,&QPushButton::clicked);
    //下方Bar尝试 //ui->downWidget
    ui->leftBar->hide();
    //通过创建删除的方式来进行更新

    QCPTextElement *title = new QCPTextElement(ui->plot, "路线示意图（不包括孤立站点）", QFont("sans", 12, QFont::Bold));
    connect(ui->plot->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->plot->xAxis2, SLOT(setRange(QCPRange)));
    connect(ui->plot->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->plot->yAxis2, SLOT(setRange(QCPRange)));
    ui->plot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);
    ui->plot->plotLayout()->insertRow(0);
    ui->plot->plotLayout()->addElement(0, 0, title);
    title->setTextColor(QColor(138,180,219));    //设置标题的颜色

    //重用的透明方法对Material无效，这是因为这些控件的颜色是绘制上去的
//    accountLineEditM->setAttribute(Qt::WA_TranslucentBackground,true);
//    accountLineEditM->setStyleSheet("background-color:transparent;");
//    accountLineEditM->setWindowOpacity(0.5);
//    accountLineEditM->useThemeColors();
//    QSizePolicy policy = accountLineEdit->sizePolicy();
//    policy.setHorizontalPolicy(QSizePolicy::Expanding);
//    accountLineEdit->setSizePolicy(policy);
}

MainWindow::~MainWindow()
//析构函数
{
    //删掉ui
    delete ui;
    //删掉线程
    m_workThread.quit();
    m_workThread.wait();
}

void MainWindow::onReceivResult(const QString &str)
{
    qDebug() << "onReceivResult:" << str;
}

void MainWindow::warmingInit()
//实现弹出动效提示框的初始化方法
{
    //这是初始化硬编码
    QVBoxLayout *layout = new QVBoxLayout;
    //ui->rightWidget->setLayout(layout);
    QWidget *widget = new QWidget;
    layout->addWidget(widget);
    QWidget *canvas = new QWidget;
    canvas->setStyleSheet("QWidget { background: white; }");
    layout->addWidget(canvas);
    layout->setContentsMargins(20, 20, 20, 20);
    layout = new QVBoxLayout;
    canvas->setLayout(layout);
    canvas->setMaximumHeight(300);
    m_dialog->setParent(ui->rightWidget);
    QWidget *dialogWidget = new QWidget;
    QVBoxLayout *dialogWidgetLayout = new QVBoxLayout;
    dialogWidget->setLayout(dialogWidgetLayout);
    contentWarm->setText("");
    contentWarm->setContentsMargins(0,70,0,0);
    contentWarm->setStyleSheet("color:black;");
    dialogWidgetLayout->addWidget(contentWarm);
    contentWarm->setAlignment( Qt::AlignCenter);
    QtMaterialFlatButton *closeButton = new QtMaterialFlatButton("知道了");
    dialogWidgetLayout->addWidget(closeButton);
    dialogWidgetLayout->setAlignment(closeButton, Qt::AlignBottom | Qt::AlignCenter);
    closeButton->setMaximumWidth(150);
    QVBoxLayout *dialogLayout = new QVBoxLayout;
    m_dialog->setWindowLayout(dialogLayout);
    dialogWidget->setMinimumHeight(250);
    dialogLayout->addWidget(dialogWidget);
    connect(closeButton, SIGNAL(pressed()), m_dialog, SLOT(hideDialog()));
}

void MainWindow::warming(QString title, QString content )
//调用即可弹出动效提示框
//参数： title：已经作废，传了也没用  content：提示框里面的内容
{
//    QMessageBox::information(NULL,title, content,
//                             QMessageBox::Yes/* | QMessageBox::No, QMessageBox::Yes*/);
    this->contentWarm->setText(content);
    this->contentWarm->setAlignment( Qt::AlignCenter);
    this->contentWarm->setStyleSheet("color:black;");
    this->m_dialog->showDialog();
}

void MainWindow::progressInit()
//实现弹出加载转圈的初始化方法
{

}

void MainWindow::progressing()
{
    this->m_dialog->layout()->addWidget(this->m_progress);
    //this->m_dialog->

}

void MainWindow::endProgressing()
{
    this->m_dialog->hideDialog();
    this->m_progress->hide();
}

void MainWindow::snackBarInit()
//实现弹出动效下边栏的初始化方法
{
    QVBoxLayout *layout = new QVBoxLayout;
    //setLayout(layout);
    QWidget *widget = new QWidget;
    layout->addWidget(widget);
    QWidget *canvas = new QWidget;
    canvas->setStyleSheet("QWidget { background: white; }");
    layout->addWidget(canvas);
    layout->setContentsMargins(20, 20, 20, 20);
    layout = new QVBoxLayout;
    canvas->setLayout(layout);
    canvas->setMaximumHeight(300);
    m_snackbar->setParent(this);
}

void MainWindow::snackBar(QString text)
//调用即可弹出动效下边栏
//参数： text：下边栏里面的内容
{
    m_snackbar->addMessage(text);
}

void MainWindow::connectFun()
//将前端控件关联到接口类的方法中
//以及，实现基本的ui内部控件关联
{
    function fun;//功能接口类
    //auto fun = new function;

    fun.moveToThread(&m_workThread);

    userID = -1;//根据登录信息发生变化

    //设置信号与槽函数examples
    //connect(ui->PB,&QPushButton::clicked,[this](){ui->LB->setText("wenzi");});
    //connect(ui->PB,SIGNAL(clicked()),this,SLOT(fun1()));
    //connect(ui->pushButton,&QPushButton::clicked,this,&MainWindow::fun2);

    //硬编码实现上方无边框栏的所有基本功能
    //包括最大化、最小化、关闭、拖动窗口等功能
    setResizeableAreaWidth(5);
    setTitleBar(ui->titleBar);

    //实现最大化、最小化、关闭、拖动窗口的功能关联
    QWidget *spacer = new QWidget;
    spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    addIgnoreWidget(spacer);
    ui->topLeftWidget->setAttribute(Qt::WA_TransparentForMouseEvents);
    connect(ui->minButton,&QToolButton::clicked,[this](){showMinimized();});
    connect(ui->closeButton,&QToolButton::clicked,[this](){close();});
    connect(ui->maxButton,&QToolButton::clicked,[this](){
        if(isMaximized())
            showNormal();
        else
            showMaximized();
        });
//    ui->titleBar->addWidget(spacer);
//    ui->titleBar->addWidget(ui->minButton);
//    ui->titleBar->addWidget(ui->maxButton);
//    ui->titleBar->addWidget(ui->closeButton);


    //Login And Register
    //注册与登录相关控件与功能关联
    ui->rightUpWidgetLable1->setText("注册与登录");
    ui->stackedWidget->setCurrentIndex(4);
    ui->loginAndRegisterTabWidget->setCurrentIndex(0);
    ui->leftButton1->hide();
    ui->leftButton2->hide();
    ui->leftButton3->hide();
    ui->leftButton4->hide();
    ui->leftButton5->hide();
    ui->siteChooseComboBox->clear();
    ui->siteChooseComboBox->addItems(fun.getSitesList());
    ui->siteChooseComboBox->hide();
    connect(ui->loginAndRegisterTabWidget,&QTabWidget::tabBarClicked,[this,&fun](){
        ui->siteChooseComboBox->clear();
        ui->siteChooseComboBox->addItem("<负责站点>");
        QModelIndex index = ui->siteChooseComboBox->model()->index(0, 0);
        QVariant v(0);
        ui->siteChooseComboBox->model()->setData(index, v, Qt::UserRole - 1);
        //ui->siteChooseComboBox->model()->setData();
        ui->siteChooseComboBox->addItems(fun.getSitesList());
        ui->siteChooseComboBox->setCurrentIndex(0);
        });

    connect(ui->loginButton,&QPushButton::clicked,[this,&fun](){
        QString result = fun.login(ui->accountLineEdit->text(),ui->passWordLineEdit->text());
        if(result=="Success"){
            setBars(fun.getResponse(userID));
            userID = (ui->accountLineEdit->text()).toInt();
            //qDebug()<<userID;
            ui->stackedWidget->setCurrentIndex(0);
            ui->rightUpWidgetLable1->setText("个人资料页");
            ui->leftButton1->show();
            ui->leftButton2->show();
            ui->leftButton3->show();
            ui->leftButton4->show();
            ui->leftButton5->show();
//            //根据权限让一些按钮消失
//            if(fun.getResponse(userID) == 0){}
//            else if(fun.getResponse(userID) == 1){
//                ui->leftButton2->hide();}
//            else{ui->leftButton2->hide();
//                ui->leftButton3->hide();}
            warming("登录结果","登录成功！");
            }
        else warming("登录结果", "登录失败:"+result);
        });
    ui->permissionLabelComboBox->addItem("高级管理员");
    ui->permissionLabelComboBox->addItem("站点管理员");
    ui->permissionLabelComboBox->addItem("业务客户");
    ui->permissionLabelComboBox->setCurrentIndex(2);
    //在这里加了一段Material构件，因为实在没地方放了
    //推荐码动效控件硬编码
    QtMaterialTextField *RecommendationLineEditM = new QtMaterialTextField;
    RecommendationLineEditM->setLabel("推荐码(选填)");
    RecommendationLineEditM->setMinimumWidth(250);
    RecommendationLineEditM->setStyleSheet("background-color:transparent;");
    ui->registerWidgetM->layout()->addWidget(RecommendationLineEditM);
    RecommendationLineEditM->hide();
    connect(RecommendationLineEditM,&QtMaterialTextField::textChanged,
            ui->passWordLineEdit_2,&QLineEdit::setText);
    connect(ui->permissionLabelComboBox,&QComboBox::currentTextChanged,
        [this,RecommendationLineEditM](){
        if(ui->permissionLabelComboBox->currentIndex()==0)
            RecommendationLineEditM->show();
        else
            RecommendationLineEditM->hide();
        });

    connect(ui->registerButton,&QPushButton::clicked,[this,&fun,RecommendationLineEditM](){
        if(ui->siteChooseComboBox->currentIndex() == 0 &&
           ui->permissionLabelComboBox->currentIndex() == 1)
        {warming("","请选择负责站点");return;}
        QString result = fun.registering(ui->accountLineEdit_2->text(),
                                   ui->passWordLineEdit_2->text(),
                                   ui->nickNameLabelLineEdit->text(),
                                   ui->permissionLabelComboBox->currentIndex(),
                                   ui->siteChooseComboBox->currentText(),
                                   RecommendationLineEditM->text() );
        if(result=="Success"){
            ui->loginAndRegisterTabWidget->setCurrentIndex(0);
            warming("注册结果","注册成功！");}
        else warming("注册结果", "注册失败:"+result);
        });
    connect(ui->permissionLabelComboBox,&QComboBox::currentTextChanged,[this](){
        if(ui->permissionLabelComboBox->currentIndex()==1)
            ui->siteChooseComboBox->show();
        else
            ui->siteChooseComboBox->hide();
        });

    //上方提示文字搭配的相应图标
    QPixmapCache::setCacheLimit(1);
    QPixmap tempPix;
    tempPix.load(":/icons/information.svg");
    topPixs.append(tempPix);
    tempPix.load(":/icons/route.svg");
    topPixs.append(tempPix);
    tempPix.load(":/icons/siteInfo.svg");
    topPixs.append(tempPix);
    tempPix.load(":/icons/data.svg");
    topPixs.append(tempPix);
    tempPix.load(":/icons/exit.svg");
    topPixs.append(tempPix);
    //Left Buttons
    ui->rightUpWidgetLable2->setPixmap(topPixs[4]);
    connect(ui->leftButton1,&QPushButton::clicked,[this](){
        ui->stackedWidget->setCurrentIndex(0);
        ui->rightUpWidgetLable2->setPixmap(topPixs[0]);
        ui->rightUpWidgetLable1->setText("个人资料页");});
    connect(ui->leftButton2,&QPushButton::clicked,[this](){
        ui->stackedWidget->setCurrentIndex(1);
        ui->rightUpWidgetLable2->setPixmap(topPixs[1]);
        ui->rightUpWidgetLable1->setText("站点与路线规划页");});
    connect(ui->leftButton3,&QPushButton::clicked,[this](){
        ui->stackedWidget->setCurrentIndex(2);
        ui->rightUpWidgetLable2->setPixmap(topPixs[2]);
        ui->rightUpWidgetLable1->setText("单站点物流管理页");});
    connect(ui->leftButton4,&QPushButton::clicked,[this](){
        ui->stackedWidget->setCurrentIndex(3);
        ui->rightUpWidgetLable2->setPixmap(topPixs[3]);
        ui->rightUpWidgetLable1->setText("运单档案页");});
    connect(ui->leftButton5,&QPushButton::clicked,[this](){
        userID = -1;
        ui->rightUpWidgetLable2->setPixmap(topPixs[4]);
        ui->leftButton1->hide();
        ui->leftButton2->hide();
        ui->leftButton3->hide();
        ui->leftButton4->hide();
        ui->leftButton5->hide();
        tabs0->hide();
        tabs1->hide();
        tabs2->hide();
        ui->stackedWidget->setCurrentIndex(4);
        ui->rightUpWidgetLable1->setText("注册与登录");
        });

    //Personal Infomation
    //个人信息页面功能关联
    ui->infoTextBrowser->setText(fun.getPersonalInfo(userID));
    connect(ui->infoTabWidget,&QTabWidget::tabBarClicked,[this,&fun](){
        ui->infoTextBrowser->setText(fun.getPersonalInfo(userID));});
    connect(ui->leftButton1,&QPushButton::clicked,[this,&fun](){
        ui->infoTextBrowser->setText(fun.getPersonalInfo(userID));});
    connect(ui->newPWButton,&QPushButton::clicked,[this,&fun](){
        QString result = fun.setNewPW(userID,ui->oldPW->text(),ui->newPW->text());
        if(result=="Success") warming("密码设置结果","修改成功！");
        else warming("密码设置结果", "设置失败:"+result);
        });
    connect(ui->newNameButton,&QPushButton::clicked,[this,&fun](){
        QString result = fun.setNewName(userID,ui->newName->text());
        if(result=="Success") warming("昵称设置结果","修改成功！");
        else warming("昵称设置结果", "设置失败:"+result);
        });

    //Sites Managment
    //站点管理页面功能关联
    QStringList strList;
    strList <<"驿站"<<"中转站点";//位置上来说分别是0和1
    ui->newSiteClassBox->addItems(strList);
    connect(ui->newSiteButton,&QPushButton::clicked,[this,&fun](){
        QString result = fun.newSite(ui->newSiteIDLineEdit->text(),ui->newSiteXLineEdit->text(),
                                     ui->newSiteYLineEdit->text(),ui->newSiteClassBox->currentIndex());
        if(result=="Success") snackBar("设置成功！");
        else snackBar("设置结果:"+result);
        });
    strList = fun.getSitesList();
    ui->delSiteIDBox->addItems(strList);
    ui->newFromComboBox->addItems(strList);
    ui->newToComboBox->addItems(strList);
    ui->delFromComboBox->addItems(strList);
    ui->delToComboBox->addItems(strList);

    connect(ui->plotButton,&QPushButton::clicked,[this,&fun](){
        //图表更新
        customPlotInit(fun.getWay());
        });
    connect(ui->wayTabWidget,&QTabWidget::tabBarClicked,[this,&fun](){
        //ComboBox更新
        ui->delSiteIDBox->clear();
        ui->newFromComboBox->clear();
        ui->newToComboBox->clear();
        ui->delFromComboBox->clear();
        ui->delToComboBox->clear();;//delete old box
        auto temp = fun.getSitesList();//后端说该函数调用次数太多了，于是每次connect只调用一次
        ui->delSiteIDBox->addItems(temp);
        ui->newFromComboBox->addItems(temp);
        ui->newToComboBox->addItems(temp);
        ui->delFromComboBox->addItems(temp);
        ui->delToComboBox->addItems(temp);//refresh box
        });
    connect(ui->delSiteButton,&QPushButton::clicked,[this,&fun](){
        QString result = fun.delSite(ui->delSiteIDBox->currentText());
        if(result=="Success") snackBar("设置成功！");
        else snackBar( "设置结果:"+result);
        });
    connect(ui->newWayButton,&QPushButton::clicked,[this,&fun](){
        QString result = fun.newWay(ui->newFromComboBox->currentText(),ui->newToComboBox->currentText(),
                                    ui->wayTimeLineEdit->text(),ui->wayFeeLineEdit->text());
        if(result=="Success") snackBar("设置成功！");
        else snackBar( "设置结果:"+result);
        });
    connect(ui->delWayButton,&QPushButton::clicked,[this,&fun](){
        QString result = fun.delWay(ui->delFromComboBox->currentText(),ui->delToComboBox->currentText());
        if(result=="Success") snackBar("删除成功！");
        else snackBar( "设置结果:"+result);
        });

    //Site Information Management
    //站点信息管理页面功能关联
    //初始化图表控件
    customPlotInit(fun.getWay());
    QStringList standardState;
    //standardState: 0      1        2      3      4       5      6
    standardState<<"全部"<<"截留"<<"运送中"<<"待取"<<"完成"<<"破损"<<"完整";//标准状态的选栏内容直接在前端添加
    ui->siteStatusComboBox->addItems(standardState);
    ui->siteComboBox->addItems(fun.getSitesList());
    auto temp = fun.getTerminalList();
    ui->mailFromComboBox->addItems(temp);
    ui->mailToComboBox->addItems(temp);
    QStringList header;
    header<<"货物编号"<<"用户编号"<<"发货地"<<"收货地"<<"发货人姓名"<<"收货人姓名"
          <<"发货人电话号"<<"收货人电话号"<<"运输单号"<<"货物当前位置"<<"发货时间"<<"备注";
    ui->siteInfoTableWidget->setColumnCount(NUMATTR);
    ui->siteFuncTableWidget->setColumnCount(NUMATTR);
    ui->siteInfoTableWidget->setHorizontalHeaderLabels(header);
    ui->siteFuncTableWidget->setHorizontalHeaderLabels(header);
    connect(ui->siteGoodTab,&QTabWidget::tabBarClicked,[this,&fun](){
        ui->siteComboBox->clear();
        ui->mailFromComboBox->clear();
        ui->mailToComboBox->clear();//delete old box
        ui->siteComboBox->addItems(fun.getSitesList());
        auto temp = fun.getTerminalList();
        ui->mailFromComboBox->addItems(temp);
        ui->mailToComboBox->addItems(temp);//refresh box
        });
    connect(ui->siteStatusButton,&QPushButton::clicked,[this](){ui->siteSearchLineEdit->clear();});
    connect(ui->siteStatusButton,&QPushButton::clicked,[this,&fun](){
        QVector<QStringList> siteGoodInfo = fun.getSiteGoodInfo(ui->siteComboBox->currentText(),
                                                               ui->siteStatusComboBox->currentIndex(),
                                                               ui->siteSearchLineEdit->text());
        ui->siteInfoTableWidget->setRowCount(siteGoodInfo.size());
        for (int i = 0;i < siteGoodInfo.size() ; i++)
            for(int j = 0;j < NUMATTR ; j++)
                ui->siteInfoTableWidget->setItem(i,j,new QTableWidgetItem(siteGoodInfo[i][j]));
        ui->siteInfoTableWidget->resizeColumnsToContents();
        ui->siteInfoTableWidget->resizeRowsToContents();
        /*ui->siteComboBox->clear();
        ui->mailFromComboBox->clear();
        ui->mailToComboBox->clear();//delete old box
        ui->siteComboBox->addItems(fun.getSitesList());
        ui->mailFromComboBox->addItems(fun.getSitesList());
        ui->mailToComboBox->addItems(fun.getSitesList());//refresh box*/
        //本想做刷新站点列表，但是刷新完如何回到上一次选中状态是个问题
        });
    connect(ui->siteSearchButton,&QPushButton::clicked,[this,&fun](){
        QVector<QStringList> siteGoodInfo = fun.getSiteGoodInfo(ui->siteComboBox->currentText(),
                                                               ui->siteStatusComboBox->currentIndex(),
                                                               ui->siteSearchLineEdit->text());
        ui->siteInfoTableWidget->setRowCount(siteGoodInfo.size());
        for (int i = 0;i < siteGoodInfo.size() ; i++)
            for(int j = 0;j < NUMATTR ; j++)
                ui->siteInfoTableWidget->setItem(i,j,new QTableWidgetItem(siteGoodInfo[i][j]));
        ui->siteInfoTableWidget->resizeColumnsToContents();
        ui->siteInfoTableWidget->resizeRowsToContents();
        });
    ui->siteInfoTableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);//NoEdit
    ui->siteInfoTableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);  //整行选中的方式
    connect(ui->siteInfoTableWidget,&QTableWidget::clicked,[this](){
        ui->siteFuncTableWidget->setRowCount(1);
        int row = ui->siteInfoTableWidget->currentRow();
        //qDebug()<<"currentRow()"<<row;
        QString tempStr;
        for(int j = 0;j < NUMATTR ; j++){
            tempStr = ui->siteInfoTableWidget->item(row,j)->text();
            qDebug() << tempStr;
            ui->siteFuncTableWidget->setItem(0,j,new QTableWidgetItem(tempStr));}
        ui->siteFuncTableWidget->resizeColumnsToContents();
        });
    ui->siteFuncTableWidget->setRowCount(1);
    for(int j = 0;j < NUMATTR ; j++)
        ui->siteFuncTableWidget->setItem(0,j,new QTableWidgetItem(""));
    ui->siteFuncTableWidget->resizeColumnsToContents();
    connect(ui->siteFuncTableRefreshButton,&QPushButton::clicked,[this](){
        ui->siteFuncTableWidget->setRowCount(1);
        for(int j = 0;j < NUMATTR ; j++)
            ui->siteFuncTableWidget->setItem(0,j,new QTableWidgetItem(""));
        ui->siteFuncTableWidget->resizeColumnsToContents();
        });
    connect(ui->siteFuncAdd,&QPushButton::clicked,[this,&fun](){
        QString result = fun.addGoodInfo(ui->siteFuncTableWidget->item(0,0)->text(),
                        ui->siteFuncTableWidget->item(0,1)->text(),
                        ui->siteFuncTableWidget->item(0,2)->text(),
                        ui->siteFuncTableWidget->item(0,3)->text(),
                        ui->siteFuncTableWidget->item(0,4)->text(),
                        ui->siteFuncTableWidget->item(0,5)->text(),
                        ui->siteFuncTableWidget->item(0,6)->text(),
                        ui->siteFuncTableWidget->item(0,7)->text(),
                        ui->siteFuncTableWidget->item(0,8)->text(),
                        ui->siteFuncTableWidget->item(0,9)->text(),
                        ui->siteFuncTableWidget->item(0,10)->text(),
                        ui->siteFuncTableWidget->item(0,11)->text());
        if(result=="Success") warming("添加信息结果","添加成功！");
        else warming("添加信息结果", "添加失败:"+result);
        });
    connect(ui->siteFuncChange,&QPushButton::clicked,[this,&fun](){
        QString result = fun.editGoodInfo(ui->siteFuncTableWidget->item(0,0)->text(),
                        ui->siteFuncTableWidget->item(0,1)->text(),
                        ui->siteFuncTableWidget->item(0,2)->text(),
                        ui->siteFuncTableWidget->item(0,3)->text(),
                        ui->siteFuncTableWidget->item(0,4)->text(),
                        ui->siteFuncTableWidget->item(0,5)->text(),
                        ui->siteFuncTableWidget->item(0,6)->text(),
                        ui->siteFuncTableWidget->item(0,7)->text(),
                        ui->siteFuncTableWidget->item(0,8)->text(),
                        ui->siteFuncTableWidget->item(0,9)->text(),
                        ui->siteFuncTableWidget->item(0,10)->text(),
                        ui->siteFuncTableWidget->item(0,11)->text());
        if(result=="Success") warming("修改信息结果","修改成功！");
        else warming("修改信息结果", "修改失败:"+result);
        });
    connect(ui->siteFuncDel,&QPushButton::clicked,[this,&fun](){
        QString result = fun.delGoodInfo(ui->siteFuncTableWidget->item(0,0)->text());
        if(result=="Success") warming("归档信息结果","归档成功！");
        else warming("归档信息结果", "归档失败:"+result);
        });

    //Mail Managment
    //寄件页面功能关联
    ui->moneyTableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);//NoEdit
    ui->moneyTableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);  //整行选中的方式
    QStringList moneyHeader;
    moneyHeader<<"方案类型"<<"详情介绍";
    ui->moneyTableWidget->setColumnCount(2);
    ui->moneyTableWidget->setHorizontalHeaderLabels(moneyHeader);
    double costOfPushing[3];
    costOfPushing[0] = 0;
    costOfPushing[1] = 0;
    costOfPushing[2] = 0;

    //connect(this, startRunning, m_worker, &Worker::on_doSomething);
    //connect(&m_workThread, &QThread::finished, &fun, &QObject::deleteLater);
    //connect(&fun, &function::resultReady, this, &MainWindow::onReceivResult);
    //======
    //connect(ui->pushButton, &QPushButton::clicked, this, &MainWindow::ThreadStart);
    //connect(m_workerThread, &QThread::started, worker, &WorkThread::start1);
    //======
    //connect(ui->mailButton,&QPushButton::clicked, this, &MainWindow::ThreadStart);

    connect(ui->mailButton,&QPushButton::clicked,[this,&fun](){
        //测试初始化加载转圈图标效果
        //progressing(); //开始转圈

        QString str1 = ui->mailFromComboBox->currentText();
        QString str2 = ui->mailToComboBox->currentText();

        qDebug()<<"============线程调用开始============";
//        QFuture<
//          QVector<QStringList>
//            > future = QtConcurrent::run([&str1,&str2,&fun]() -> QVector<QStringList> {
//            qDebug() << str1 << str2;
//            return fun.mailPushing(str1,str2);
//            });

//        QtConcurrent::run([this,&str1,&str2,&fun]() {
//            qDebug()<<"线程第一行:"<< str1 << str2;;
//            auto result = fun.mailPushing(str1,str2);
//            qDebug()<<"QVector<QStringList> result = fun.mailPushing(str1,str2);";
//            emit this->mailButtonWaitting(result);
//            qDebug()<<"emit this->mailButtonWaitting(result);";
//        });
        qDebug()<<"============线程调用结束============";
//        QTest::qSleep ( 1000 ) ;
        QVector<QStringList> pushing = fun.mailPushing(ui->mailFromComboBox->currentText(),
                                                       ui->mailToComboBox->currentText());
        //不用线程的写法
        emit this->mailButtonWaitting(pushing);
        });

    connect(this,&MainWindow::mailButtonWaitting,[this,&fun,&costOfPushing](QVector<QStringList> item){
        QVector<QStringList> pushing = item;
        qDebug()<<"pushing拿到了future值";
        ui->moneyTableWidget->setRowCount(pushing.size());
        //double tempNum;
        for (int i = 0;i < pushing.size() ; i++){
            for(int j = 0;j < 2 ; j++)
                ui->moneyTableWidget->setItem(i,j,new QTableWidgetItem(pushing[i][j]));
            //qDebug()<<pushing[i][2].toDouble();
            //tempNum = pushing[i][2].toDouble();
            costOfPushing[i] = pushing[i][2].toDouble();
            }
        ui->moneyTableWidget->resizeColumnsToContents();
        ui->moneyTableWidget->resizeRowsToContents();
        ui->moneyLcdNumber->display(costOfPushing[ui->moneySlider->value()]);

        //endProgressing(); //结束转圈
        //qDebug()<<"转圈结束";
        });
    ui->moneySlider->setMaximum(0);
    ui->moneySlider->setMaximum(2);
    ui->moneySlider->setSingleStep(1);
    ui->moneySlider->setPageStep(1);
    ui->moneySlider->setValue(1);
    ui->moneySlider->setTickPosition(QSlider::TicksAbove);
    connect(ui->moneyTableWidget,&QTableWidget::currentCellChanged,ui->moneySlider,&QSlider::setValue);
    connect(ui->moneyTableWidget,&QTableWidget::currentCellChanged,[this,&costOfPushing](){
        ui->moneyLcdNumber->display(costOfPushing[ui->moneySlider->value()]);
        });
    connect(ui->moneySlider,&QSlider::valueChanged,[this,&costOfPushing](){
        ui->moneyLcdNumber->display(costOfPushing[ui->moneySlider->value()]);
        });
    connect(ui->moneyPushButton,&QPushButton::clicked,[this,&fun](){
        QString result = fun.pay(ui->mailFromComboBox->currentText(),ui->mailToComboBox->currentText(),
                                 ui->moneyUserIDLabelLineEdit->text(),
                                 ui->moneyConsignerNameLineEdit->text(),ui->moneyConsignerTeleLineEdit->text(),
                                 ui->moneyConsigneeNameLineEdit->text(),ui->moneyConsigneeTeleLineEdit->text(),
                                 ui->moneySlider->value(),ui->moneyLcdNumber->value());
        if(result=="Success") {
            //根据初步想法，应该会在这里改成一个二维码窗口
            warming("支付结果", "假装有个二维码\n支付成功！");
            }
        else warming("支付结果", "支付结果:"+result);
            });


    //Waybill File
    //档案管理页面功能关联
    ui->allGoodTableWidget->setColumnCount(NUMATTR);
    ui->allGoodTableWidget->setHorizontalHeaderLabels(header);
    ui->allGoodElementComboBox->addItems(header);
    QVector<QStringList> allGoodInfo = fun.getAllGoodInfo();
    ui->allGoodTableWidget->setRowCount(allGoodInfo.size());
    for (int i = 0;i < allGoodInfo.size() ; i++)
        for(int j = 0;j < NUMATTR ; j++)
            ui->allGoodTableWidget->setItem(i,j,new QTableWidgetItem(allGoodInfo[i][j]));
    ui->allGoodTableWidget->resizeColumnsToContents();
    ui->allGoodTableWidget->resizeRowsToContents();
    ui->allGoodTableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);//NoEdit
    ui->allGoodTableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);  //整行选中的方式
    //待补充
    connect(ui->refreshAllGoodButton,&QPushButton::clicked,[this,&fun](){
        QVector<QStringList> allGoodInfo = fun.getAllGoodInfo();
        ui->allGoodTableWidget->setRowCount(allGoodInfo.size());
        for (int i = 0;i < allGoodInfo.size() ; i++)
            for(int j = 0;j < NUMATTR ; j++)
                ui->allGoodTableWidget->setItem(i,j,new QTableWidgetItem(allGoodInfo[i][j]));
        ui->allGoodTableWidget->resizeColumnsToContents();
        ui->allGoodTableWidget->resizeRowsToContents();
        ui->allGoodLineEdit->clear();
        });
    connect(ui->allGoodPushButton,&QPushButton::clicked,[this,&fun](){
        QVector<QStringList> accurateGoodInfo = fun.getAccurateGoodInfo(
                             ui->allGoodElementComboBox->currentIndex(),ui->allGoodLineEdit->text());
        ui->allGoodTableWidget->setRowCount(accurateGoodInfo.size());
        //qDebug()<<accurateGoodInfo.size();
        for (int i = 0;i < accurateGoodInfo.size() ; i++)
            for(int j = 0;j < NUMATTR ; j++)
                ui->allGoodTableWidget->setItem(i,j,new QTableWidgetItem(accurateGoodInfo[i][j]));
        ui->allGoodTableWidget->resizeColumnsToContents();
        ui->allGoodTableWidget->resizeRowsToContents();
        });

}



void MainWindow::setBars(int property)
//根据不同权限改变下方按纽栏的按钮数量
//参数： property：权限等级
{
    if(property==0){tabs0->show();tabs0->setCurrentTab(0);ui->siteFuncDel->show();}
    else if(property==1){tabs1->show();tabs1->setCurrentTab(0);ui->siteFuncDel->hide();}
    else if(property==2){tabs2->show();tabs2->setCurrentTab(0);ui->siteFuncDel->hide();}
}

void MainWindow::barsInit()
//下方动效按纽栏的初始化的硬编码
{
    tabs0->addTab("个人资料");
    tabs0->addTab("增删站点");
    tabs0->addTab("站点信息");
    tabs0->addTab("运单档案");
    tabs0->addTab("退出登录");
    connect(tabs0,&QtMaterialTabs::currentChanged,[this](){
        if(tabs0->currentIndex()==0)ui->leftButton1->click();
        else if(tabs0->currentIndex()==1)ui->leftButton2->click();
        else if(tabs0->currentIndex()==2)ui->leftButton3->click();
        else if(tabs0->currentIndex()==3)ui->leftButton4->click();
        else if(tabs0->currentIndex()==4)ui->leftButton5->click();
        });
    tabs0->setBackgroundColor(QColor(73,78,143, 255));
    ui->downWidget->layout()->addWidget(tabs0);
    tabs0->hide();
    tabs1->addTab("个人资料");
    tabs1->addTab("增删站点");
    tabs1->addTab("站点信息");
    tabs1->addTab("退出登录");
    connect(tabs1,&QtMaterialTabs::currentChanged,[this](){
        if(tabs1->currentIndex()==0)ui->leftButton1->click();
        else if(tabs1->currentIndex()==1)ui->leftButton2->click();
        else if(tabs1->currentIndex()==2)ui->leftButton3->click();
        else if(tabs1->currentIndex()==3)ui->leftButton5->click();
        });
    tabs1->setBackgroundColor(QColor(73,78,143, 255));
    ui->downWidget->layout()->addWidget(tabs1);
    tabs1->hide();
    tabs2->addTab("个人资料");
    tabs2->addTab("运单档案");
    tabs2->addTab("退出登录");
    connect(tabs2,&QtMaterialTabs::currentChanged,[this](){
        if(tabs2->currentIndex()==0)ui->leftButton1->click();
        else if(tabs2->currentIndex()==1)ui->leftButton4->click();
        else if(tabs2->currentIndex()==2)ui->leftButton5->click();
        });
    tabs2->setBackgroundColor(QColor(73,78,143, 255));
    ui->downWidget->layout()->addWidget(tabs2);
    tabs2->hide();
    connect(ui->aboutUs,&QToolButton::clicked,[this](){warming("",
            "本项目为西北大学学生团队作业\n\n\
团队组成：金雨展、刘英杰、李春毅、李云帆、田震、谢箫\n\n\
2021.3");});
    //setting
    ui->settingWidget->hide();
    drawer->setParent(ui->centralWidget);
    drawer->setClickOutsideToClose(true);
    drawer->setOverlayMode(true);
    connect(ui->setting, SIGNAL(pressed()), drawer, SLOT(openDrawer()));
    drawer->setAutoRaise(1);
    QVBoxLayout *drawerLayout = new QVBoxLayout;
    drawer->setDrawerLayout(drawerLayout);
    drawerLayout->addWidget(ui->settingWidget);
    ui->settingWidget->show();
    //drawerLayout->addStretch(3);
    drawer->setContentsMargins(10, 0, 0, 0);
    //drawerLayout->addWidget(new QPushButton("abc"));
    ui->themeComboBox->addItem("暗色主题");
    ui->themeComboBox->addItem("亮色主题(待填坑)");
    //connect(ui->themeComboBox,&QComboBox::currentIndexChanged,this,&MainWindow::setTheme);
    connect(ui->themeComboBox,&QComboBox::currentTextChanged,[this](){
        setTheme(ui->themeComboBox->currentIndex());
        });
    }

    void MainWindow::setTheme(int themeIndex)
    //读取某css作为主题，目前只完整做了一个主题
    //初始化函数中读取某css作为默认主题
    {
        if(themeIndex == 0)
        {
            QFile file("://MainWindowD.qss");
            file.open(QIODevice::ReadOnly|QIODevice::Text);
            QString str = file.readAll();
            setStyleSheet(str);
        }
        else if(themeIndex == 1)
        {
            QFile file("://MainWindowL.qss");
            file.open(QIODevice::ReadOnly|QIODevice::Text);
            QString str = file.readAll();
            setStyleSheet(str);
        }
    }

    void MainWindow::customPlotInit(wayInfo info)
    {
        ui->plot->clearGraphs();
//        QList<double> point1;
//        QList<double> point2;
//        QList<QString> name;
//        QList<double> weight;

        ui->plot->addGraph();
        ui->plot->graph(0)->setPen(QPen(Qt::blue)); // line color blue for first graph
        ui->plot->graph(0)->setBrush(QBrush(QColor(0, 0, 255, 20))); // first graph will be filled with translucent blue
        ui->plot->addGraph();
        //ui->plot->graph(1)->setPen(QPen(Qt::red)); // line color red for second graph

        QVector<double> point1XList;
        QVector<double> point1YList;
        QVector<QString> point1Name;
        QVector<double> point2XList;
        QVector<double> point2YList;
        QVector<QString> point2Name;

        for(int i=0;i<info.name.length()/2;i++)
        {
            //把点信息进行分类
            if(info.name[2*i].contains(QRegExp("^\\d+$")))
            {
                point1XList << info.point1[2*i];
                point1YList << info.point1[2*i+1];
                point1Name << info.name[2*i];
            }
            else
            {
                point2XList << info.point1[2*i];
                point2YList << info.point1[2*i+1];
                point2Name << info.name[2*i+1];
            }
            if(info.name[2*i+1].contains(QRegExp("^\\d+$")))
            {
                point1XList << info.point2[2*i];
                point1YList << info.point2[2*i+1];
                point1Name << info.name[2*i];
            }
            else
            {
                point2XList << info.point2[2*i];
                point2YList << info.point2[2*i+1];
                point2Name << info.name[2*i+1];
            }

            //一段路程的表达式代码化
            double x1 = info.point1[2*i];
            double y1 = info.point1[2*i+1];
            double x2 = info.point2[2*i];
            double y2 = info.point2[2*i+1];
            QVector<double> lineXList;
            QVector<double> lineYList;
            lineXList << x1 << x2;
            lineYList << y1 << y2;
            QPen drawPen;
            drawPen.setColor(Qt::blue);
            drawPen.setWidth(1);
            QCPGraph * curGraph = ui->plot->addGraph();
            curGraph->setPen(drawPen);
            curGraph->setLineStyle(QCPGraph::lsLine);
            curGraph->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, 2));
            curGraph->setData(lineXList, lineYList);


        }

        //画点：区别两种站点
        {
        QPen drawPen;
        drawPen.setColor(Qt::red);
        drawPen.setWidth(4);
        QCPGraph* curGraph = ui->plot->addGraph();
        curGraph->setPen(drawPen);
        curGraph->setLineStyle(QCPGraph::lsNone);
        curGraph->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, 6));
        curGraph->setData(point1XList, point1YList);
        QCPItemText *m_sameTimeTextTip = new QCPItemText(ui->plot);
        m_sameTimeTextTip->setPositionAlignment(Qt::AlignTop|Qt::AlignHCenter);
        m_sameTimeTextTip->position->setType(QCPItemPosition::ptAbsolute);
        }
        {
        QPen drawPen;
        drawPen.setColor(Qt::green);
        drawPen.setWidth(4);
        QCPGraph* curGraph = ui->plot->addGraph();
        curGraph->setPen(drawPen);
        curGraph->setLineStyle(QCPGraph::lsNone);
        curGraph->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssPlusSquare, 6));
        curGraph->setData(point2XList, point2YList);
        QCPItemText *m_sameTimeTextTip = new QCPItemText(ui->plot);
        m_sameTimeTextTip->setPositionAlignment(Qt::AlignTop|Qt::AlignHCenter);
        m_sameTimeTextTip->position->setType(QCPItemPosition::ptAbsolute);
        }

//        QCPTextElement *title = new QCPTextElement(ui->plot, "站点示意图", QFont("sans", 12, QFont::Bold));
//        connect(ui->plot->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->plot->xAxis2, SLOT(setRange(QCPRange)));
//        connect(ui->plot->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->plot->yAxis2, SLOT(setRange(QCPRange)));
//        ui->plot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);
//        ui->plot->plotLayout()->insertRow(0);
//        ui->plot->plotLayout()->addElement(0, 0, title);
//        title->setTextColor(QColor(138,180,219));    //设置标题的颜色

        QLinearGradient plotGradient;
        plotGradient.setStart(0, 0);
        plotGradient.setFinalStop(0, 350);
        plotGradient.setColorAt(0, QColor(80, 80, 80));
        plotGradient.setColorAt(1, QColor(50, 50, 50));
        ui->plot->xAxis->setLabel("红色：中继站    绿色：驿站");
        ui->plot->xAxis->setLabelColor(Qt::white);   // 轴标签颜色
        ui->plot->setBackground(plotGradient);      // 设置背景颜色
        ui->plot->xAxis->setBasePen(QPen(Qt::white, 1));  // 轴线的画笔
        ui->plot->xAxis->setTickPen(QPen(Qt::white, 1));  // 轴刻度线的画笔
        ui->plot->xAxis->setSubTickPen(QPen(Qt::white, 1)); // 轴子刻度线的画笔
        ui->plot->xAxis->setTickLabelColor(Qt::white);  // 轴刻度文字颜色
        ui->plot->yAxis->setBasePen(QPen(Qt::white, 1));  // 轴线的画笔
        ui->plot->yAxis->setTickPen(QPen(Qt::white, 1));  // 轴刻度线的画笔
        ui->plot->yAxis->setSubTickPen(QPen(Qt::white, 1)); // 轴子刻度线的画笔
        ui->plot->yAxis->setTickLabelColor(Qt::white);  // 轴刻度文字颜色
        ui->plot->xAxis->grid()->setPen(QPen(QColor(140, 140, 140), 1, Qt::DotLine));     // 网格线(对应刻度)画笔
        ui->plot->yAxis->grid()->setPen(QPen(QColor(140, 140, 140), 1, Qt::DotLine));
        ui->plot->xAxis->grid()->setSubGridPen(QPen(QColor(80, 80, 80), 1, Qt::DotLine)); // 子网格线(对应子刻度)画笔
        ui->plot->yAxis->grid()->setSubGridPen(QPen(QColor(80, 80, 80), 1, Qt::DotLine));
        ui->plot->xAxis->grid()->setSubGridVisible(true);     // 显示子网格线
        ui->plot->yAxis->grid()->setSubGridVisible(true);
        ui->plot->xAxis->grid()->setZeroLinePen(QPen(Qt::red));   // 设置刻度为0时的网格线的画笔
        ui->plot->yAxis->grid()->setZeroLinePen(QPen(Qt::red));

    }



